using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc;
using MatrixFramework.Shared.Contracts.Monitoring;

namespace MatrixFramework.Shared.HttpApi.Controllers
{
    /// <summary>
    /// 健康检查控制器
    /// 提供标准的健康检查API接口
    /// </summary>
    [ApiController]
    [Route("api/[controller]")]
    [Produces("application/json")]
    public class HealthController : AbpControllerBase
    {
        private readonly IHealthCheckAppService _healthCheckAppService;

        public HealthController(IHealthCheckAppService healthCheckAppService)
        {
            _healthCheckAppService = healthCheckAppService;
        }

        /// <summary>
        /// 获取简单健康状态
        /// </summary>
        /// <returns>简单健康状态</returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<SimpleHealthCheckDto> GetAsync()
        {
            return await _healthCheckAppService.GetSimpleHealthAsync();
        }

        /// <summary>
        /// 获取详细健康检查报告
        /// </summary>
        /// <returns>详细健康检查报告</returns>
        [HttpGet("detailed")]
        public async Task<DetailedHealthCheckDto> GetDetailedAsync()
        {
            return await _healthCheckAppService.GetDetailedHealthAsync();
        }

        /// <summary>
        /// 获取特定组件的健康状态
        /// </summary>
        /// <param name="componentName">组件名称</param>
        /// <returns>组件健康状态</returns>
        [HttpGet("components/{componentName}")]
        public async Task<ComponentHealthDto> GetComponentAsync(string componentName)
        {
            return await _healthCheckAppService.GetComponentHealthAsync(componentName);
        }
    }
}